package org.mokusakura.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.zhenzi.sms.ZhenziSmsClient;
import org.mokusakura.domain.AlipayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfig {
    @Value("${zhenzi.appId}")
    private String appId;
    @Value("${zhenzi.apiUrl}")
    private String apiUrl;
    @Value("${zhenzi.appSecret}")
    private String appSecret;
    @Autowired
    private AlipayConfig alipayConfig;

    @Bean
    public ZhenziSmsClient getZhenziSmsClient() {
        return new ZhenziSmsClient(apiUrl, appId, appSecret);
    }

    @Bean
    public AlipayClient getAlipayClient() {
        return new DefaultAlipayClient(alipayConfig.getServerUrl(),
                                       alipayConfig.getAppId(),
                                       alipayConfig.getAppPrivateKey(),
                                       alipayConfig.getFormat(),
                                       alipayConfig.getCharset(),
                                       alipayConfig.getAppPublicKey(),
                                       alipayConfig.getSignType());
    }
}
